function PatchTestQ4
m = createModel();
m.preAnalysis();

n = m.getMesh().countDofs();
kk = inf.jlinalg.Array2DMatrix(n,n);
m.assembleKt(kk);
r = zeros(1,n);
r = m.assembleR(r);
u = kk.getValues()\r
m.setX(1,u);
for i=0:3
    m.getMesh().getNode(i).getUHatLocal()
end
plotDeformedMesh(m.getMesh(),1);

% try
%     m.solve();
% catch f
%     s = lasterror();
%     emsg = {''; ['Java Exception has been caught:'];
%         s.message; ''};
%     for i=1:size(s.stack,1),
%         emsg = [emsg; [s.stack(i).file '::' s.stack(i).name
%             '() at ' num2str(s.stack(i).line)]];
%     end
%     if size(s.stack,1) > 0,
%         emsg = [emsg; ''];
%     end
%     dialogPanel(fig.ubsMain.figure,'Error',emsg);
% end
end

function y = createModel()
ms = fem2.Mesh();

l = 1;
h = 1;
n1 = ms.addNode(fem2.Node(0, 0));
n2 = ms.addNode(fem2.Node(l, 0));
n3 = ms.addNode(fem2.Node(l, h));
n4 = ms.addNode(fem2.Node(0, h));

f1 = ms.addFace(fem2.Face([n1 n2 n3 n4]));

ms.setNumberOfFields(2);

% element and model
E = 2;
nu = 0.3;
t = 1.0;
rho = 0.0;
ss = fem2.enu.State.PLANE_STRESS;
cm = fem2.StVenantKirchhoffMM(E, nu, t, rho, ss);

y = fem2.Model(ms);
e1 = fem2.StructuralElement(f1, cm);
y.addElement(e1);

% constraint
c1 = fem2.Constraint([0 0]);
c2 = fem2.Constraint([1 0]);
c3 = fem2.Constraint([0 1]);
n1.setConstraint(c1);
n2.setConstraint(c2);
n4.setConstraint(c3);

%force
F = 0.5;
l1 = fem2.Force(y.getMesh().getNode(1), [F 0]);
l2 = fem2.Force(y.getMesh().getNode(2), [F 0]);
y.addLoad(l1);
y.addLoad(l2);

end
